<template>
  <div>
    <el-table
      ref="table"
      v-loading="listLoading"
      :header-cell-style="{background:'#F5F4F7'}"
      :data="model.list"
      border
      fit
      stripe
      highlight-current-row
      :height="tableHeight"
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        width="60"
        label="序号"
        align="center"
      />
      <el-table-column
        prop="strreceipttypename"
        label="单据类型"
        width="180"
      />
      <el-table-column
        prop="strbilltemplatename"
        label="单据模板"
        min-width="180"
      />
      <el-table-column
        prop="intpreset"
        label="数据来源"
        width="180"
      >
        <template v-slot="scope">
          {{ scope.row.intpreset|preset }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" label="启用/停用" width="100">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.blnisinactive"
            active-color="#3FBEB8"
            inactive-color="#B7B7B7"
            :active-value="0"
            :inactive-value="1"
            @change="changeState(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="190"
        align="center"
        class-name="mb0"
        fixed="right"
      >
        <template v-slot="scope">
          <el-button type="text" :disabled="!!scope.row.intpreset" @click="editEvent(scope.row)">编辑</el-button>
          <el-button type="text" @click="deleteEvent(scope.row)">删除</el-button>
          <el-button type="text" @click="mobileSetEvent(scope.row)">移动端设置</el-button>

        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-if="paging.total > 0"
      background
      :current-page.sync="paging.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="paging.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="paging.total"
      @size-change="queryListByPage('search')"
      @current-change="queryListByPage"
    />
  </div>
</template>
<script>
import { findSearchPageFn, deleteFn, updateBlnisinactiveFn } from '@/api/system/bill-setting/bill-template'
import calculateCommonTableHeight from '@/layout/mixin/calculateCommonTableHeight'
export default {
  name: 'BillTemplateTableArea',
  components: { },
  mixins: [calculateCommonTableHeight],
  props: {

  },
  data() {
    const token = this.$store.getters.decodeToken
    return {
      token,
      model: {
        list: [],
        rules: {}
      },
      listLoading: false,
      searchForm: {
      },
      paging: {
        total: 0,
        page: 1,
        size: 10
      }
    }
  },
  created() {
  },
  methods: {
    // 获取列表查询
    query(searchForm) {
      this.searchForm = JSON.parse(JSON.stringify(searchForm))
      this.paging.page = 1
      this.queryListByPage()
    },
    queryListByPage(str = '') {
      if (str === 'search') {
        this.paging.page = 1
      }
      this.listLoading = true
      findSearchPageFn(
        this.searchForm,
        this.paging.page,
        this.paging.size
      ).then(res => {
        if (res.code === 20000) {
          this.paging.total = res.data.total
          this.model.list = res.data.rows
        }
      }).finally(() => {
        this.listLoading = false
      })
    },

    // 删除
    deleteEvent(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteFn(row.lngbilltemplateid).then(res => {
          if (res.code === 20000) {
            this.$message({
              showClose: true,
              message: res.message,
              type: 'success'
            })
            this.queryListByPage()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 停启用
    changeState(row) {
      updateBlnisinactiveFn(row).then(res => {
        if (res.code === 20000) {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success'
          })
          this.queryListByPage()
        }
      })
    },
    // 查看
    mobileSetEvent(row) {
      this.$emit('mobileSet', row)
    },
    // 编辑
    editEvent(row) {
      this.$emit('edit', row)
    }
  }
}
</script>

<style lang="scss" scoped>
.status{
  text-align: right;
  font-size: 14px;
  color: #333;
}
</style>

